package com.kuiandjie.web;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kuiandjie.entity.Employee;
import com.kuiandjie.service.EmployeeService;

public class NewProServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		Employee emp = (Employee) session.getAttribute("employee");
		String name = emp.getName();
		
		if("tom".equals(name)) {
			List<Employee> emList = getAllEmployee();
			
			request.setAttribute("emList", emList);
			request.getRequestDispatcher("WEB-INF/views/newpro.jsp").forward(request, response);
		} else {
			response.sendError(404, "页面不存在");
		}
	}

	private List<Employee> getAllEmployee() {
		EmployeeService es = new EmployeeService();
		return es.findAll();
	}
}
